﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;

namespace Model
{
    [Table("Order")]
    public class Order : BaseModel
    {
        public string OrderNo { get; set; }
        public int? CustomerId { get; set; }
        public DateTime OrderDate { get; set; }
        public DateTime DeliveryDate { get; set; }
        public string DeliveryAddress { get; set; }
        public string OtherInformation { get; set; }
        public string Status { get; set; }
        public bool DeliveryInternal { get; set; }

        public virtual Customer Customer { get; set; }
        public virtual ICollection<OrderDetail> Details { get; set; }        

        public virtual ICollection<DeliveryDetail> DeliveryDetails { get; set; }

        //Chiết khấu
        public decimal? Discount { get; set; }

        public decimal? DiscountLD { get; set; }        

        public string Recipient { get; set; }

        public string RecipientPhone { get; set; }

        public string SendEmail { get; set; }

        public string SendMessage { get; set; }

        public bool Vat { get; set; }

        public bool SendWithEmail { get; set; }

        public decimal? Liability { get; set; }

        public string IsSendNotification { get; set; }

        [NotMapped]
        public string CustomerName
        {
            get
            {
                if (CustomerId.HasValue)
                {
                    return Customer.FullName;
                }
                return string.Empty;
            }
        }

        [NotMapped]
        public string DeliveryType
        {
            get
            {
                if (DeliveryInternal)
                    return "Nội thành";
                else
                    return "Ngoại thành";
            }
        }

        public string DeliveryName
        {
            get
            {
                if(DeliveryDetails != null && DeliveryDetails.Count > 0)
                {
                    foreach(DeliveryDetail item in DeliveryDetails)
                    {
                        return item.Delivery.DeliveryNo;
                    }
                }

                return string.Empty;
            }
        }
    }

    [NotMapped]
    public class OrderTemplate
    {
        public int Id { get; set; }
        public string OrderNo { get; set; }
        public string Customer { get; set; }
        public string Status { get; set; }
        public DateTime DeliveryDate { get; set; }
        public string SendMessage { get; set; }
        public string SendEmail { get; set; }

        public string SendReport { get; set; }
        public string DeliveryInternal { get; set; }
        public int ParentId { get; set; }
        public int CustomerId { get; set; }
        public string Recipient { get; set; }        
    }

    [NotMapped]
    public class SearchOrder
    {
        public int Id { get; set; }
        public string OrderNo { get; set; }
        public int? CustomerId { get; set; }
        public DateTime OrderDate { get; set; }
        public DateTime DeliveryDate { get; set; }
        public string DeliveryAddress { get; set; }
        public string OtherInformation { get; set; }
        public string Status { get; set; }
        public string CustomerName { get; set; }
        public int? DeliveryTime { get; set; }
        public bool DeliveryInternal { get; set; }
    }
}
